package org.com.blbl.partitionCount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class PartitionCountReducer extends Reducer<Text, LongWritable, Text, IntWritable>  {

    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Reducer<Text, LongWritable, Text, IntWritable>.Context context) throws IOException, InterruptedException {
        //定义次数结果
        IntWritable result = new IntWritable();
        //统计每个分区变量
        int count = 0;
        //遍历一组数组，统计次数，取出该组的所有的Value
        for (LongWritable value : values){
            //所有的value进行累加，就是该单词出现的总次数
            count += value.get();
        }
        result.set(count);
        context.write(key, result);
    }
}
